package com.heima.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.admin.service.AdChannelService;
import com.heima.api.schedule.WemediaFeign;
import com.heima.model.admin.dots.ChannelDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@RequiredArgsConstructor
public class AdChannelController {

    private final WemediaFeign wemediaFeign;

    private final AdChannelService channelService;

    /**
     * 频道名称模糊分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageResponseResult channelPage(@RequestBody ChannelDto dto){
        return wemediaFeign.wemediaList(dto);
    }

    /**
     * 新增频道
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel channel) {
        return wemediaFeign.saveChannel(channel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return wemediaFeign.deleteById(id);
    }

    /**
     * 修改频道
     * @param channel
     * @return
     */
    @PostMapping("/update")
    @GlobalTransactional
    public ResponseResult updateChannel(@RequestBody WmChannel channel){
        return wemediaFeign.updateChannel(channel);
    }

}
